package logic

import (
	"context"
	"ewaimai/waimairpc/cache"
	"ewaimai/waimairpc/models"

	"ewaimai/waimairpc/internal/svc"
	"ewaimai/waimairpc/waimairpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsCarDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsCarDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsCarDelLogic {
	return &GoodsCarDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsCarDelLogic) GoodsCarDel(in *waimairpc.GoodsCarDelRequest) (*waimairpc.GoodsCarDelResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	var u models.User
	u.ID = uint(in.UserId)
	if err = u.GetUserById(int(in.UserId)); err != nil {
		logx.Errorf("用户不存在")
	}
	var g models.Goods
	if err = g.GetGoods(int(in.GoodsId)); err != nil {
		logx.Error("商品不存在")
	}
	if err = cache.CartDel(int(in.UserId), int(in.GoodsId)); err != nil {
		logx.Error("删除失败")
	}
	return &waimairpc.GoodsCarDelResponse{
		GoodsId: int64(g.ID),
	}, nil
}
